package database.node;

import java.util.ArrayList;

public class ListNode {
	public int indexRelation;
	public ArrayList<Node> listAttribute = new ArrayList<Node>();
	
	public void printListNode() {
		System.out.print(indexRelation);
		System.out.print("(");
		for(int i = 0; i < listAttribute.size() - 1; i++) {
			System.out.print(listAttribute.get(i).attName + "["+listAttribute.get(i).index+"]");
		}
		System.out.print(listAttribute.get(listAttribute.size() - 1).attName + "["+listAttribute.get(listAttribute.size() - 1).index+"]");
		System.out.print(")");
	}
	
	/**
	 * tìm xem trong này có indexAtt hay ko?
	 * nếu có thì trả về node att đó
	 * ko thì trả về null;
	 * @param indexAtt
	 * @return
	 */
	public Node findAttribute(int indexAtt) {
		for (Node att : listAttribute) {
			if(att.index == indexAtt) {
				return att;
			}
		} 
		return null;
	}
	
	public int findIndexOfListSynAttribute(String [] lsAtt) {
		int index = 0;
		boolean isFinish = false;
		for(int i = 0; i < listAttribute.size() && !isFinish; i++) {
			for(int j = 0; j < lsAtt.length && !isFinish; j ++) {
				if(listAttribute.get(i).attName.equals(lsAtt[j])) {
					isFinish = true;
					index = listAttribute.get(i).index;
				}
			}
		}
		return index;
	}
}
